package br.com.ffm.praticas.facade;

import java.sql.SQLException;

import br.com.ffm.praticas.bean.City;
import br.com.ffm.praticas.dao.CityDAO;

public class CityFACADE {
	
	private static CityFACADE cityFACADE;
	private static CityDAO cityDAO;
	
	private CityFACADE(){
		cityDAO = new CityDAO();
	}
	
	/**
	 * Method that returns an unique instance of CityFACADE
	 * @return An unique instance of CityFACADE
	 */
	public static CityFACADE getInstance(){
		if(cityFACADE == null){
			cityFACADE = new CityFACADE();
		}
		return cityFACADE;
	}
	
	/**
	 * Method that search a City by ID
	 * @param id The ID of the City to be found
	 * @return If found, returns the City else returns null
	 * @throws SQLException 
	 */
	public City getCity(int id) throws SQLException{
		return cityDAO.getCity(id);
	}
	
	/**
	 * Method that search a City by ID
	 * @param description The Description of the City to be found
	 * @return If found, returns the City else returns null
	 * @throws SQLException 
	 */
	public City getCity(String description) throws SQLException{
		return cityDAO.getCity(description);
	}
	
	/**
	 * Method that count the number of cities
	 * @return The number of cities
	 * @throws SQLException 
	 */
	public int count() throws SQLException{
		return cityDAO.getCities().size();
	}

}
